import { constantRoutes , asyncRoutes } from '@/router'

const state = {
    routes: constantRoutes   //所有用户默认拥有静态路由
}

const mutations = {
    setRoutes (state, newRouters) {
        state.routes = [...constantRoutes , ...newRouters]
    }
}

const actions = {
    filterRoutes (context,menus) {
        const routes = [];
        menus.forEach( key => {
            routes.push(...asyncRoutes.filter(item => 
                item.name === key 
            ))
        })
        context.commit('setRoutes', routes)
        console.log(menus,'routes');
        return routes
    }
}
export default {
    namespaced: true,
    state,
    mutations,
    actions
}